﻿using System.Collections.Generic;
using com.loto.Common.DBUtility;
using com.huigo.Framework.Model;

namespace com.huigo.Framework.BLL
{
    public class SupInfo
    {
        public static List<Model.SupInfo> GetSupInfoDropList()
        {
            List<string> fields = new List<string>()
            {
                "SUP_ID",
                "SUP_NAME"
            };
            List<WhereStatement> whereList = new List<WhereStatement>()
            {
                new WhereStatement("SUP_STATUS","=",((int)Dict.IsActive.Yes).ToString(),"")
            };
            List<OrderByStatement> orderList = new List<OrderByStatement>()
            {
                new OrderByStatement("SUP_NAME",true)
            };
            return SqlServerDal.SupInfo.GetItems(fields, whereList, orderList, null);
        }

        public static bool AddSupInfo(Model.SupInfo supInfo)
        {
            return SqlServerDal.SupInfo.Insert(supInfo, null);
        }

        public static List<Model.SupInfo> GetSupList(string supName, int pageSize, int pageIndex)
        {
            List<string> fields = new List<string>() 
             {
                "SUP_ID",
                "SUP_NAME",
                "SUP_TYPE",
                "SUP_STATUS",
                "SUP_MARK"
             };
            List<OrderByStatement> OrderByStatement = new List<OrderByStatement>() 
             {
                 new OrderByStatement("SUP_STATUS",false),
                 new OrderByStatement("SUP_CREATED_ON",false)
             };
            List<WhereStatement> whereList = null;
            if (!string.IsNullOrEmpty(supName))
            {
                whereList = new List<WhereStatement>()
                {
                    new WhereStatement("SUP_NAME","LIKE","'%"+supName+"%'","OR"),
                     new WhereStatement("SUP_MARK","LIKE","'%"+supName+"%'","")
               };
            }
            List<Model.SupInfo> supList = null;
            int recordCount = 0;
            int pageCount = 0;
            supList = SqlServerDal.SupInfo.GetItemsByProc(fields, null, whereList, OrderByStatement, "[PROC_PAGINATION_OUT]", pageSize, pageIndex, out recordCount, out pageCount, null);
            supList.ForEach(delegate(Model.SupInfo info)
            {
                info.RecordCount = recordCount;
                info.PageCount = pageCount;
            });
            return supList;

        }

        public static Model.SupInfo GetSupInfoById(long id)
        {
            Model.SupInfo supInfo = new Model.SupInfo();
            supInfo.SupId = id;
            List<string> fields = new List<string>() 
             {
                "SUP_ID",
                "SUP_NAME",
                "SUP_TYPE",
                "SUP_STATUS",
                "SUP_MARK"
             };
            return SqlServerDal.SupInfo.GetItem(supInfo, fields, null, null);
        }

        public static bool UpdateSupInfo(long sid, Model.SupInfo supInfo)
        {
            List<WhereStatement> whereList = new List<WhereStatement>()
            {
                    new WhereStatement("SUP_ID","=",sid.ToString(),"")
            };
            return SqlServerDal.SupInfo.Update(supInfo, whereList, null);
        }
    }
}
